#ifndef keyboard_H
#define keyboard_H

#include <QWidget>
#include <QButtonGroup>
#include <Qt>
#include <QMouseEvent>
#include <QFile>
#include <QLabel>
#include <QMessageBox>

#include <QLineEdit>
#include <QTextEdit>
#include <QPlainTextEdit>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QTextBrowser>

#include <QKeyEvent>

class INPUTMethod;

typedef struct
{
  int start;
  int end;
} RECORD;

enum EinputMethod{english,pinying,wubi,wuhua,chinese};

namespace Ui {
    class keyboard;
}

class keyboard : public QWidget
{
    Q_OBJECT

public:
    explicit keyboard(INPUTMethod *ipm,QWidget *parent=0);
    ~keyboard();

protected:
    void mousePressEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    void mouseMoveEvent(QMouseEvent *);
    void keyPressEvent ( QKeyEvent  *e);
    //void keyReleaseEvent(QKeyEvent * e);

private:

    void  initKeyBoard();   //
    void SetKeyBoard();
    void SetKeyBar();
    void setKeyValue( int id);

    void  setKeyValueForCaplock();
    //void  setKeyValueForShift();

    void setBar(int ,bool);
    void moveKeys(int);

    void setCharValue( int  keyId);

public slots:
    void keyPressed(int);
    void barPressed(int);

signals:
    void SendInputMessage(char);
    void SendEnter();
    void SendBackspace();
    void SenEscape();

private slots:
    void on_clearBtn_clicked();


    void on_key_Space_clicked();

private:
    QPoint dragPosition;
    bool moveAble;
    RECORD record[15];
    QStringList clist;
//    bool findNothing;
    char firstFlag;

    Ui::keyboard *ui;
    QButtonGroup *btnKeys;
    QButtonGroup *btnBar;
    EinputMethod method;

    bool CapLockFlag,ShiftFlag,CharFlage;
    int currentPage;
    QKeyEvent* transkey(int x,int y);
    bool transPy(QString pyInput);
    QLineEdit *keyRev;

    QFile file;
    void showPage(int index);
    int pageCount;
    void changeInputMethod();
    void changeSize();
    void clearBar();
    void clearBarToBtn();
    bool openFile(char);

};

#endif // keyboard_H

